#include <iostream>
#include <cstdlib>
#include <fstream>
#include "core.h"
#include "elimination.h"
/*
template <typename T>
std::ostream& operator << (std::ostream& os, const Matrix<T>& mat)
{
    os << "matrix ( " << mat.m() << " x " << mat.n() << " ) :\n";
    for (int i = 0; i < mat.m(); ++i) {
        os << '\t';
        for (int j = 0; j < mat.n(); ++j) {
            os << mat(i, j) << ' ';
        }
        os << std::endl;
    }
    return os;
}
*/

using namespace RubbishLinearAlgebra;

int main()
{
    Matrix<float> A(4, 3), B(4, 3);

    srand(time(NULL));
    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 3; ++j) {
            A(i, j) = float(rand() % 1000);
            B(i, j) = float(rand() % 1000);
        }
    }

    std::cout << A << B;

    auto C = A + B;
    std::cout << C;
    std::cout << (A - 1000);

    std::cout << RubbishLinearAlgebra::equals_zero(1e-16) << std::endl;

    std::ifstream ifs("input.txt");
    int m, n;
    ifs >> m >> n;
    Matrix<float> X(m, n);
    X.from_istream(ifs);

    std::cout << X;

    int rank = to_rref(X);

    std::cout << X;
    std::cout << "rank: " << rank << std::endl;

    X.eye(-1);
    std::cout << X;
    rank = to_rref(X);
    std::cout << "rank: " << rank << std::endl;
    std::cout << X;
}
